<template>
  <div class="login-page">
    <div class="svg-top">
      <!--?xml version="1.0" encoding="utf-8"?-->
      <svg
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        height="1337"
        width="1337"
      >
        <defs>
          <path
            id="path-1"
            opacity="1"
            fill-rule="evenodd"
            d="M1337,668.5 C1337,1037.455193874239 1037.455193874239,1337 668.5,1337 C523.6725684305388,1337 337,1236 370.50000000000006,1094 C434.03835568300906,824.6732385973953 6.906089672974592e-14,892.6277623047779 0,668.5000000000001 C0,299.5448061257611 299.5448061257609,1.1368683772161603e-13 668.4999999999999,0 C1037.455193874239,0 1337,299.544806125761 1337,668.5Z"
          ></path>
          <linearGradient
            id="linearGradient-2"
            x1="0.79"
            y1="0.62"
            x2="0.21"
            y2="0.86"
          >
            <stop
              offset="0"
              stop-color="rgb(88,62,213)"
              stop-opacity="1"
            ></stop>
            <stop
              offset="1"
              stop-color="rgb(23,215,250)"
              stop-opacity="1"
            ></stop>
          </linearGradient>
        </defs>
        <g opacity="1">
          <use
            xlink:href="#path-1"
            fill="url(#linearGradient-2)"
            fill-opacity="1"
          ></use>
        </g>
      </svg>
    </div>

    <div class="svg-bottom">
      <!--?xml version="1.0" encoding="utf-8"?-->
      <svg
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        height="896"
        width="967.8852157128662"
      >
        <defs>
          <path
            id="path-2"
            opacity="1"
            fill-rule="evenodd"
            d="M896,448 C1142.6325445712241,465.5747656464056 695.2579309733121,896 448,896 C200.74206902668806,896 5.684341886080802e-14,695.2579309733121 0,448.0000000000001 C0,200.74206902668806 200.74206902668791,5.684341886080802e-14 447.99999999999994,0 C695.2579309733121,0 475,418 896,448Z"
          ></path>
          <linearGradient id="linearGradient-3" x1="0.5" y1="0" x2="0.5" y2="1">
            <stop
              offset="0"
              stop-color="rgb(40,175,240)"
              stop-opacity="1"
            ></stop>
            <stop
              offset="1"
              stop-color="rgb(18,15,196)"
              stop-opacity="1"
            ></stop>
          </linearGradient>
        </defs>
        <g opacity="1">
          <use
            xlink:href="#path-2"
            fill="url(#linearGradient-3)"
            fill-opacity="1"
          ></use>
        </g>
      </svg>
    </div>

    <div class="login-content">
      <div class="login-card">
        <div class="login-header">
          <h1>XXXXX系统</h1>
        </div>

        <a-form
          ref="formRef"
          :model="formState"
          :rules="loginRules"
          class="login-form"
          layout="vertical"
        >
          <a-form-item name="username">
            <a-input
              v-model:value="formState.username"
              placeholder="请输入用户名"
              size="large"
              allow-clear
            >
              <template #prefix>
                <UserOutlined />
              </template>
            </a-input>
          </a-form-item>

          <a-form-item name="password">
            <a-input-password
              v-model:value="formState.password"
              placeholder="请输入密码"
              size="large"
              allow-clear
              @pressEnter="handleLogin"
            >
              <template #prefix>
                <LockOutlined />
              </template>
            </a-input-password>
          </a-form-item>

          <a-form-item class="py-4">
            <a-button type="primary" size="large" block @click="handleLogin">
              立即登录
            </a-button>
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// 组件命名
defineOptions({
  name: 'Login',
});

// 导入Vue组合式API
import { reactive, ref, onMounted, onBeforeUnmount } from 'vue';
import { useRouter } from 'vue-router';
import {
  UserOutlined,
  LockOutlined,
  DesktopOutlined,
  PartitionOutlined,
  StarOutlined,
  BookOutlined as IconBook,
} from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import { login } from '@/api/manage.api';

const router = useRouter();
const formRef = ref();

const formState = reactive({
  username: 'admin',
  password: '123456',
});

const loginRules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    {
      min: 2,
      max: 20,
      message: '用户名长度在 2 到 20 个字符',
      trigger: 'blur',
    },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur' },
  ],
};

const handleLogin = () => {
  formRef.value.validate().then(() => {
    login({
      user_name: 'admin',
      password: '123456',
    }).then(result => {
      router.push('/home');
    });
  });
};

// 生命周期钩子
onMounted(() => {
  console.log('组件已挂载');
});

onBeforeUnmount(() => {
  console.log('组件即将卸载');
});
</script>
<style>
html, body{
  overflow: hidden;
}
</style>
<style scoped lang="scss">

.login-page {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: linear-gradient(
    135deg,
    rgba(255, 126, 51, 0.9),
    rgba(255, 215, 0, 0.8),
    rgba(74, 144, 226, 0.9)
  );
  background-size: 400% 400%;
  animation: gradientShift 8s ease infinite;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.login-content {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

.login-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 18px;
  padding: 48px 40px;
  width: 100%;
  width: 430px;
  height: ;
  max-width: 420px;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.1),
    0 16px 32px rgba(255, 126, 51, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: cardFadeIn 0.8s ease-out;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 40px;

  h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ff7e33, #4a90e2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
  }
}

.svg-top {
  position: absolute;
    top: -900px;
    right: -300px;
}

.svg-bottom {
  position: absolute;
    bottom: -500px;
    left: -200px;
}
</style>

